package com.example.myapplication.TouchDemo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class TestView2 extends View {

    int color;
    public TestView2(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setColor(int color) {
        this.color = color;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(color);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Toast.makeText(this.getContext(),"onTouchEvent..."+event.getAction(),Toast.LENGTH_SHORT).show();
        ///onTouch、onTouchEvent等事件传递，是从里向外，是包裹关系。并非肉眼的层叠关系。
        if(color == Color.RED){
            return true;
        }else{
            return false;
        }
    }
}
